package com.jielin.handling.service.xsky.impl;

import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.jielin.handling.service.xsky.XskyService;
import com.jielin.handling.third.xsky.demo.XSKYS3Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

@Service
@Slf4j
public class XskyServiceImpl implements XskyService {

    @Override
    public void uploadObject(String bucketName, String key, File file) {
        log.info("对象上传start...");
        try {
            XSKYS3Service.uploadObject(bucketName, key, file);
        } catch (Exception e) {
            log.error("对象上传异常：{}", e.getMessage());
        }
        log.info("对象上传end...");
    }

    @Override
    public void uploadObject(String bucketName, String key, String content) throws SdkClientException {
        XSKYS3Service.uploadObject(bucketName, key, content);
    }

    @Override
    public void uploadObjectThrows(String bucketName, String key, File file) throws SdkClientException {
        XSKYS3Service.uploadObjectThrows(bucketName, key, file);
    }

    @Override
    public void uploadObjectForInputStream(String bucketName, String key, byte[] bytes, ObjectMetadata metadata) throws SdkClientException {
        XSKYS3Service.uploadObjectForInputStream(bucketName, key, bytes, metadata);
    }

    @Override
    public void uploadObjectForInputStream(String bucketName, String key, InputStream inputStream, ObjectMetadata metadata) throws SdkClientException {
        XSKYS3Service.uploadObjectForInputStream(bucketName, key, inputStream, metadata);
    }

    @Override
    public void downloadObject(String bucketName, String key, String newFile) {
        log.info("对象下载start...");
        try {
            XSKYS3Service.downloadObject(bucketName, key, newFile);
        } catch (Exception e) {
            log.error("对象下载异常：{}", e.getMessage());
        }
        log.info("对象下载end...");
    }

    @Override
    public void downloadObjectThrows(String bucketName, String key, String newFile) throws SdkClientException, IOException {
        XSKYS3Service.downloadObjectThrows(bucketName, key, newFile);
    }

    @Override
    public void deleteObject(String bucketName, String key) {
        log.info("对象删除start...");
        try {
            XSKYS3Service.deleteObject(bucketName, key);
        } catch (Exception e) {
            log.error("对象删除异常：{}", e.getMessage());
        }
        log.info("对象删除end...");
    }

    @Override
    public void copyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey, ObjectMetadata metadata) throws SdkClientException {
        XSKYS3Service.copyObjectThrows(sourceBucketName, sourceKey, destinationBucketName, destinationKey, metadata);
    }

}